package com.inossem.warehousestorage_inossem.adapter.outStorage;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.inossem.utils.listener.NoDoubleClickListener;
import com.inossem.warehousestorage_inossem.R;
import com.inossem.warehousestorage_inossem.bean.outStorage.OutStorageOperatorBean;

import java.util.List;

/**
 * Created by leij on 2017/6/6.
 */

public class ReturnSelectOperatorListAdapter extends BaseAdapter {

    private Context mContext;
    private List<OutStorageOperatorBean.DataBean.ReceiverListBean> mSelectReceiverList;
    private LayoutInflater inflater;
//    private ReceiveSelectReceiverActivity.ReceiveSelectReceiverListener mReceiveSelectReceiverListener;
//
//    public ReturnSelectOperatorListAdapter(Context context, List<OutStorageOperatorBean.DataBean.ReceiverListBean> selectReceiverList, ReceiveSelectReceiverActivity.ReceiveSelectReceiverListener receiveSelectReceiverListener) {
//        mContext = context;
//        mSelectReceiverList = selectReceiverList;
//        mReceiveSelectReceiverListener = receiveSelectReceiverListener;
//        inflater = LayoutInflater.from(context);
//    }

    @Override
    public int getCount() {
        return mSelectReceiverList.size();
    }

    @Override
    public Object getItem(int position) {
        return mSelectReceiverList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        OutStorageOperatorBean.DataBean.ReceiverListBean receiverItem = mSelectReceiverList.get(position);
        ViewHolder viewHolder;
        if (convertView == null || (convertView != null && convertView.getTag() == null)) {
            convertView = inflater.inflate(R.layout.view_in_storage_select_receiver_list, null);
            viewHolder = new ViewHolder();
            //初始化控件
            initView(viewHolder, convertView);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        //初始化数据
        initData(mContext, viewHolder, convertView, receiverItem);
        return convertView;
    }

    private void initView(ViewHolder viewHolder, View view) {
        viewHolder.id = (TextView) view.findViewById(R.id.id);
        viewHolder.name = (TextView) view.findViewById(R.id.name);
        viewHolder.userName = (TextView) view.findViewById(R.id.userName);
        viewHolder.company = (TextView) view.findViewById(R.id.company);
        viewHolder.department = (TextView) view.findViewById(R.id.department);
        viewHolder.roleName = (TextView) view.findViewById(R.id.roleName);
        viewHolder.roleCode = (TextView) view.findViewById(R.id.roleCode);
        viewHolder.phone = (TextView) view.findViewById(R.id.phone);
    }

    private void initData(Context context, ViewHolder viewHolder, View view, OutStorageOperatorBean.DataBean.ReceiverListBean receiverItem) {
        viewHolder.id.setText(receiverItem.getId());
        viewHolder.name.setText(receiverItem.getName());
        viewHolder.userName.setText(receiverItem.getUserName());
        viewHolder.company.setText(receiverItem.getCompany());
        viewHolder.department.setText(receiverItem.getDepartment());
        viewHolder.roleName.setText(receiverItem.getRoleName());
        viewHolder.roleCode.setText(receiverItem.getRoleCode());
        viewHolder.phone.setText(receiverItem.getPhone());
        view.setOnClickListener(new NoDoubleClickListener() {
            @Override
            public void onNoDoubleClick(View v) {
//                OutStorageReturnOverviewBean.DataBean.OperatorListBean receiveReceiver = new OutStorageReturnOverviewBean.DataBean.OperatorListBean();
//                receiveReceiver.setId(receiverItem.getId());
//                receiveReceiver.setName(receiverItem.getName());
//                receiveReceiver.setDepartment(receiverItem.getDepartment());
//                receiveReceiver.setRoleName(receiverItem.getRoleName());
//                receiveReceiver.setRoleCode(receiverItem.getRoleCode());
//                receiveReceiver.setPhone(receiverItem.getPhone());
//                OutStorageUtils.addReturnOperator(context, receiveReceiver);
//                mReceiveSelectReceiverListener.onSelectReceiver();
            }
        });
    }

    private class ViewHolder {
        private TextView id, name, userName, company, department, roleName, roleCode, phone;
    }

}
